package com.atguigu.tingshu.order.receiver;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ClassName : OrderReceiver
 * Package : com.atguigu.tingshu.order.receiver
 * Description :
 * <p>
 * Author: LHZ
 * Create: 2025/8/4 23:10
 * Version: 1.0
 */
@Slf4j
@Component
public class OrderReceiver {
    @Autowired
    private OrderInfoService orderInfoService;

    @SneakyThrows
    @RabbitListener(queues = MqConst.QUEUE_CANCEL_ORDER)
    public void cancelOrder(Long orderId, Channel channel, Message message){
        if(orderId != null){
            log.info("[订单服务]监听到延迟关单消息：{}", orderId);
            //调用取消订单方法
            orderInfoService.cancelOrder(orderId);
        }
        //确认消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}